const constantStatus = require('./constantStatus')

// 返回状态码
const resultStatus = {
  /*
   * 操作成功
   * @param {object} result 返回数据
   * @return {{code, msg, data: *}}
   * @constructor
   */
  SUCCESS: (result) => {
    const { SUCCESS_CODE: code, SUCCESS_MSG: msg } = constantStatus
    return {
      code,
      msg,
      data: result
    }
  },

  /*
   * 密码错误
   * @param {string} msg 提示
   * @returns {{msg: string, code: number}}
   * @constructor
   */
  PASSWORK: (msg = constantStatus.PASSWORK_MSG) => {
    const { PASSWORK_CODE: code } = constantStatus
    return {
      code,
      msg
    }
  },

  /*
   * 参数错误
   * @param {string} msg 提示
   * @returns {{msg: string, code: number}}
   * @constructor
   */
  PARAME: (msg = constantStatus.PARAME_MSG) => {
    const { PARAME_CODE: code } = constantStatus
    return {
      code,
      msg
    }
  },

  /*
   * 令牌过期
   * @returns {{msg: string, code: number}}
   * @constructor
   */
  TOKEN: () => {
    const { TOKEN_CODE: code, TOKEN_MSG: msg } = constantStatus
    return {
      code,
      msg
    }
  },

  /*
   * 帐户不存在
   * @param msg
   * @returns {{msg: string, code: number}}
   * @constructor
   */
  USERNULL: (msg = constantStatus.USERNULL_MSG) => {
    const { USERNULL_CODE: code } = constantStatus
    return {
      code,
      msg
    }
  },

  /*
   * 数据库操作异常
   * @param result
   * @return {{code, msg, error}}
   * @class
   */
  DBERROR: (result) => {
    const { DBERROR_CODE: code, DBERROR_MSG: msg } = constantStatus
    return {
      code,
      msg,
      error: JSON.stringify(result)
    }
  },
  /*
   * 没有查询结果
   * @returns {{msg: string, code: number}}
   * @constructor
   */
  DBNULL: () => {
    const { DBNULL_CODE: code, DBNULL_MSG: msg } = constantStatus
    return {
      code,
      msg
    }
  },

  /*
   * 其他异常
   * @param msg
   * @param data
   * @returns {{msg: string, code: number, data: string}}
   * @constructor
   */
  EXCEPTION: (msg = constantStatus.EXCEPTION_MSG) => {
    const { EXCEPTION_CODE: code } = constantStatus
    return {
      code,
      msg
    }
  },
  /*
   * 账号已存在
   * @returns {{msg: string, code: number}}
   * @constructor
   */
  USEREXIT: () => {
    const { USEREXIT_CODE: code, USEREXIT_MSG: msg } = constantStatus
    return {
      code,
      msg
    }
  },
  /*
   * 账号未激活
   * @returns {{msg: string, code: number}}
   * @constructor
   */
  USERACTION: () => {
    const { USERACTION_CODE: code, USERACTION_MSG: msg } = constantStatus
    return {
      code,
      msg
    }
  },
  /*
   * 账号已激活
   * @returns {{msg: string, code: number}}
   * @constructor
   */
  USERISACTION: () => {
    const { USERISACTION_CODE: code, USERISACTION_MSG: msg } = constantStatus
    return {
      code,
      msg
    }
  }
}

module.exports = resultStatus
